﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>部门管理</title>

<#--引入要用相对路径-->
<#include "../common/link.ftl">
    <script>
        $(function () {
            //编辑或添加按钮绑定事件，弹出编辑或增加模态框
            $(".btn_input").click(function () {
                //弹出模态框
                $("#editModal").modal("show");
                //修改模态框标题
                $(".modal-title").html("部门添加");
                //数据复原
                $("#editForm input").val('');

                //部门回显数据
                var data = $(this).data("json");
                if (data) {
                    $(".modal-title").html("部门编辑");
                    $("input[name='id']").val(data.id);
                    $("input[name='name']").val(data.name);
                    $("input[name='sn']").val(data.sn);
                }
            });


            //保存操作(模态框的保存按钮)
            $(".btn_submit").click(function () {
                //这是 jquery-form 插件，是用 ajax 发送异步请求
                $("#editForm").ajaxSubmit(function (data) {
                    checkData(data);
                })
            });

        })

    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">

<#include "../common/navbar.ftl" >
    <!--菜单回显 设置变量-->
<#assign currentMenu="department">

<#include "../common/menu.ftl" >

    <div class="content-wrapper">
        <section class="content-header">
            <h1>部门管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!-- 表单 --->
                <form class="form-inline" id="searchForm" action="/department/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                <#-- 添加部门 .btn_input-->
                    <a href="JavaScript:;" class="btn btn-success btn-input btn_input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>序号</th>
                            <th>编号</th>
                            <th>部门名称</th>
                            <th>部门编号</th>
                            <th>操作</th>
                        </tr>

                    <#-- 循环 注意要括上()，!表示可以为空，不会报错 -->
                    <#list (pageInfo.list)! as entity>
                        <tr>
                            <td>${entity_index + 1 + (qo.currentPage-1)*qo.pageSize}</td>
                            <td>${entity.id!}</td>
                            <td>
                            <#-- 查看某部门的所有员工，直接用员工列表页的高级查询部门为该部门 -->
                                <a href="/employee/list.do?deptId=${entity.id!}">
                                ${entity.name!}
                                </a>
                            </td>
                            <td>${entity.sn!}</td>
                            <td>
                            <#--编辑部门 .btn_input-->
                                <a href="JavaScript:;" data-json='${entity.jsonString}'
                                   class="btn btn-info btn-xs btn-input btn_input">
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                            <#--删除部门 .btn_delete-->
                                <a href="JavaScript:;" data-json='${entity.jsonString}'
                                   data-url="/department/delete.do?id=${entity.id!}"
                                   class="btn btn-danger btn-xs btn-delete btn_delete">
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                            </td>
                        </tr>
                    </#list>

                    </table>

                    <!--分页-->
                <#include "../common/page_plus.ftl" >

                </div>
            </div>
        </section>
    </div>

<#include "../common/footer.ftl" >
</div>

<#--部门编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">部门编辑</h4>
            </div>
            <div class="modal-body">

            <#-- 表单 -->
                <form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">部门名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" value="" placeholder="请输入部门名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">部门编号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sn" value="" placeholder="请输入部门编号">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
